package main.java.com.config;

import java.util.List;

public class PageInfo<T> {
    //每页大小
    private Integer pageSize = 5;
    //当前页码
    private Integer currPageNo = 1;
    //总页数
    private Integer totalPages = 1;
    //总条数
    private Integer totals = 0;
    //每页存储的数据集合
    private List<T> list;

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        if(pageSize<=0){
            pageSize = 5 ;
        }
        this.pageSize = pageSize;
    }

    public Integer getCurrPageNo() {
        //当设置的当前页码大于总页数时，页码为总页数
        if(currPageNo >  totalPages){
            currPageNo = totalPages;
        }
        return currPageNo;
    }

    public void setCurrPageNo(Integer currPageNo) {
        if(currPageNo <= 0){
            currPageNo = 1;
        }
        this.currPageNo = currPageNo;
    }


    public Integer getTotalPages() {
        return totalPages;
    }


    public Integer getTotals() {
        return totals;
    }

    public void setTotals(Integer totals) {
        if(totals<=0){
            totals = 0;
            totalPages  = 1;
        }else{
            if(totals % pageSize == 0){
                totalPages = totals/pageSize;
            }else{
                totalPages = totals/pageSize + 1;
            }
        }

        this.totals = totals;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    @Override
    public String toString() {
        return "PageInfo{" +
                "pageSize=" + pageSize +
                ", currPageNo=" + currPageNo +
                ", totalPages=" + totalPages +
                ", totals=" + totals +
                ", list=" + list +
                '}';
    }
}
